from django.http import HttpResponseRedirect
from django.shortcuts import redirect,reverse



def check_login(fn):
    """
    检查登录装饰器
    :param fn:
    :return:
    """
    def wrapper(request,*args,**kwargs):
        if request.session.get('is_login', False):
            return fn(request,*args,**kwargs)
        else:
            # 获取用户当前访问的url，并传递给/user/login/
            next = request.get_full_path()
            red = HttpResponseRedirect(reverse('file_manage:Login')+'?next=' + next)
            return red
    return wrapper